<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>UEditor富文本</title>
    <script type="text/javascript" src="./../../../static/js/include/_include-css.js"></script>
</head>


<body class="bg-gray">
    <div class="wrapper">
        <div class="wrapper-container">

            <div class="panel">
                <div class="panel-heading">
                    百度富文本编辑器（UEditor）
                </div>
                <div class="panel-body">
                    <textarea name="content" id="content"></textarea>
                    <p id="btns">
                    <div>
                        <button onclick="getAllHtml()">获得整个html的内容</button>
                        <button onclick="getContent()">获得内容</button>
                        <button onclick="setContent()">写入内容</button>
                        <button onclick="setContent(true)">追加内容</button>
                        <button onclick="getContentTxt()">获得纯文本</button>
                        <button onclick="getPlainTxt()">获得带格式的纯文本</button>
                        <button onclick="hasContent()">判断是否有内容</button>
                        <button onclick="setFocus()">使编辑器获得焦点</button>
                        <button onmousedown="isFocus(event)">编辑器是否获得焦点</button>
                        <button onmousedown="setblur(event)">编辑器失去焦点</button>

                    </div>
                    <div>
                        <button onclick="getText()">获得当前选中的文本</button>
                        <button onclick="insertHtml()">插入给定的内容</button>
                        <button id="enable" onclick="setEnabled()">可以编辑</button>
                        <button onclick="setDisabled()">不可编辑</button>
                        <button onclick=" ue.setHide()">隐藏编辑器</button>
                        <button onclick=" ue.setShow()">显示编辑器</button>
                        <button onclick=" ue.setHeight(300)">设置高度为300默认关闭了自动长高</button>
                    </div>

                    </p>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="./../../../static/js/include/_include-js.js"></script>
    <script type="text/javascript" src="./../../../static/plugins/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="./../../../static/plugins/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" src="./../../../static/plugins/ueditor/lang/zh-cn/zh-cn.js"> </script>
    <script>
        var ue = UE.getEditor("content");

        function isFocus(e) {
            alert(ue.isFocus());
            UE.dom.domUtils.preventDefault(e)
        }
        function setblur(e) {
            ue.blur();
            UE.dom.domUtils.preventDefault(e)
        }
        function insertHtml() {
            var value = prompt('插入html代码', '');
            ue.execCommand('insertHtml', value)
        }
        function createEditor() {
            enableBtn();
            ue;
        }
        function getAllHtml() {
            alert(ue.getAllHtml())
        }
        function getContent() {
            var arr = [];
            arr.push("使用editor.getContent()方法可以获得编辑器的内容");
            arr.push("内容为：");
            arr.push(ue.getContent());
            alert(arr.join("\n"));
        }
        function getPlainTxt() {
            var arr = [];
            arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
            arr.push("内容为：");
            arr.push(ue.getPlainTxt());
            alert(arr.join('\n'))
        }
        function setContent(isAppendTo) {
            var arr = [];
            arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
            ue.setContent('欢迎使用ueditor', isAppendTo);
            alert(arr.join("\n"));
        }
        function setDisabled() {
            ue.setDisabled('fullscreen');
            disableBtn("enable");
        }

        function setEnabled() {
            ue.setEnabled();
            enableBtn();
        }

        function getText() {
            //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
            var range = ue.selection.getRange();
            range.select();
            var txt = ue.selection.getText();
            alert(txt)
        }

        function getContentTxt() {
            var arr = [];
            arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
            arr.push("编辑器的纯文本内容为：");
            arr.push(ue.getContentTxt());
            alert(arr.join("\n"));
        }
        function hasContent() {
            var arr = [];
            arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
            arr.push("判断结果为：");
            arr.push(ue.hasContents());
            alert(arr.join("\n"));
        }
        function setFocus() {
            ue.focus();
        }
        function deleteEditor() {
            disableBtn();
            ue.destroy();
        }
        function disableBtn(str) {
            var div = document.getElementById('btns');
            var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
            for (var i = 0, btn; btn = btns[i++];) {
                if (btn.id == str) {
                    UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
                } else {
                    btn.setAttribute("disabled", "true");
                }
            }
        }
        function enableBtn() {
            var div = document.getElementById('btns');
            var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
            for (var i = 0, btn; btn = btns[i++];) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            }
        }

    </script>
</body>

</html>